package com.huaboot.framework.security.exception;

import com.huaboot.commont.core.ResultUtils;
import com.huaboot.framework.security.utils.SecurityUtil;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  认证失败处理类 返回未授权
 */
public class SecurityAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
        SecurityUtil.writeJavaScript(ResultUtils.error(cn.hutool.http.HttpStatus.HTTP_UNAUTHORIZED,"请求访问:" + request.getRequestURI() + "认证失败请重新登录"),response);
    }

}
